<template>
	<div class="myPage">
		<template v-for="item in widgetList">
			<!-- 基础组件:不可嵌套其他组件 -->
			<!-- 天气组件 -->
			<block :key="item.cid" v-if="item.type === 'weather'">
				<myWeather :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myWeather>
			</block>

			<!-- 图片pic -->
			<block :key="item.cid" v-if="item.type === 'pic'">
				<myImg :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig" :listData="listData"></myImg>
			</block>

			<!-- 标签label -->
			<block :key="item.cid" v-if="item.type === 'label'">
				<myLabel :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig" :listData="listData"></myLabel>
			</block>

			<!-- 标签scrollLabel -->
			<block :key="item.cid" v-if="item.type === 'scrollLabel'">
				<myScrollLabel :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig" :listData="listData"></myScrollLabel>
			</block>

			<!-- 按钮button -->
			<block :key="item.cid" v-if="item.type === 'button'">
				<myButton :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig" :listData="listData"></myButton>
			</block>

			<!-- 倒计时countdown -->
			<block :key="item.cid" v-if="item.type === 'countDown'">
				<myCountDown :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myCountDown>
			</block>

			<!-- 条形进度条lineProgress -->
			<block :key="item.cid" v-if="item.type === 'lineProgress'">
				<myLineProgress :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myLineProgress>
			</block>

			<!-- 输入框input -->
			<block :key="item.cid" v-if="item.type === 'input'">
				<myInput :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myInput>
			</block>

			<!-- 富文本richText -->
			<block :key="item.cid" v-if="item.type === 'richText'">
				<myRichText :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myRichText>
			</block>

			<!-- 视频video -->
			<block :key="item.cid" v-if="item.type === 'video'">
				<myVideo :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myVideo>
			</block>

			<!-- 扫码scanCode -->
			<block :key="item.cid" v-if="item.type === 'scanCode'">
				<scanCode :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></scanCode>
			</block>
			
			<!-- 标签组组件tags -->
			<block :key="item.cid" v-if="item.type === 'tags'">
				<myTags :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myTags>
			</block>
			
			<!-- 地图组件map -->
			<block :key="item.cid" v-if="item.type === 'map'">
				<myMap :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myMap>
			</block>

			<!-- 手绘图查看组件picPreview -->
			<block :key="item.cid" v-if="item.type === 'picPreview'">
				<myPicPrev :ref="item.type+item.cid" :pcid="item.cid" :pageConfig="pageConfig"></myPicPrev>
			</block>

			<!-- 容器组件layout -->
			<block :key="item.cid" v-if="item.type === 'layout'">
				<div class="layout" v-show="!item.common.isHidden" @tap="handleTap(item,listData)" :style="item.styleStr" :class="{ needShare: item.shareInfo.hasShare}">
					<button open-type="share" class="share" v-if="item.shareInfo.hasShare" :data-share="item.shareInfo.shareInfo">
						<myPage v-if="item.children.length > 0" :pcid="item.cid" :pageConfig="pageConfig" :jsonData="[]" :listData="listData" :dataBind="dataBind" :ref="'layoutPage-'+item.cid" :parentCid="item.cid"></myPage>
					</button>
					<myPage v-if="!item.shareInfo.hasShare && item.children.length > 0" :pcid="item.cid" :pageConfig="pageConfig" :jsonData="[]" :listData="listData" :dataBind="dataBind" :ref="'layoutPage-'+item.cid" :parentCid="item.cid"></myPage>
				</div>
			</block>

			<!-- scrollView组件 -->
			<block :key="item.cid" v-if="item.type === 'scrollView'">
				<div class="myScrollView" v-show="!item.common.isHidden" :style="item.styleStr" @tap.stop>
					<scroll-view :scroll-y="item.common.scrollY" :scroll-x="item.common.scrollX" :scroll-left="item.common.scrollLeft" :scroll-top="item.common.scrollTop">
						<div :style="'min-width:'+(item.common.scrollX?item.common.minWidth:1)+'rpx;min-height:'+(item.common.scrollY?item.common.minHeight:1)+'rpx;'">
							<myPage :pcid="item.cid" :pageConfig="pageConfig" :jsonData="[]" :listData="listData" :dataBind="dataBind" :ref="'scrollPage-'+item.cid" :parentCid="item.cid"></myPage>
						</div>
					</scroll-view>
				</div>
			</block>

			<!-- 列表list -->
			<block :key="item.cid" v-if="(listWidget.indexOf(item.type)>-1)">
				<div class="myList" v-if="!item.common.isHidden" :class="[item.common.direction, item.common.wrap ? 'wrap' : 'nowrap']" :style="item.styleStr" @tap.stop>
					<scroll-view v-if="item.common.direction === 'horizontal' && !item.common.wrap" scroll-x>
						<div v-for="(obj, index) in item.listArray" :key="index" class="listItem" :style="item.itemStyle+(item.type==='mutiStyleList'?'width:'+item.mutiChildren[obj.styleLink][0].common.width+'rpx;height:'+item.mutiChildren[obj.styleLink][0].common.height+'rpx;':'')" @tap="handleTap(item, obj)">
							<myPage v-if="item.type === 'mutiStyleList'" :childLevel="1" :pageConfig="pageConfig" :jsonData="item.mutiChildren[obj.styleLink]" :listData="obj" :dataBind="item.bindData"></myPage>
							<myPage v-else :pageConfig="pageConfig" :childLevel="1" :jsonData="item.children" :listData="obj" :dataBind="item.bindData"></myPage>
						</div>
						<div class="infoBox inSv">
							<u-loadmore :status="item.status" v-if="item.loadmoreShow" :margin-top="20" :margin-bottom="20"></u-loadmore>
							<u-empty text="暂无数据" mode="data" v-if="item.listArray.length === 0 && !item.loadmoreShow"></u-empty>
						</div>
					</scroll-view>
					<template v-else>
						<div class="waterLt" v-if="item.type === 'waterfall' && item.waterfallLt && item.waterfallLt.length>0">
							<myPage :pcid="item.cid" :pageConfig="pageConfig" :jsonData="[]" :ref="'listPageLt-'+item.cid" :parentCid="item.cid"></myPage>
						</div>
						<div
							v-for="(obj, index) in item.listArray"
							:key="index"
							class="listItem"
							:class="{ nomr: item.type === 'list' && (index + 1) % item.common.horizontalNum === 0 }"
							:style="item.itemStyle+(item.type==='waterfall'?'left:'+obj.l+'rpx;top:'+obj.t+'rpx;height:'+obj.h+'rpx':(item.type==='mutiStyleList'?'width:'+item.mutiChildren[obj.styleLink][0].common.width+'rpx;height:'+item.mutiChildren[obj.styleLink][0].common.height+'rpx;':''))"
							@tap="handleTap(item, obj)"
						>
							<myPage v-if="item.type !== 'waterfall' && item.type !== 'mutiStyleList'" :childLevel="1" :pageConfig="pageConfig" :jsonData="item.children" :listData="obj" :dataBind="item.bindData"></myPage>
							<myPage v-if="item.type === 'waterfall'" :childLevel="1" :pageConfig="pageConfig" :jsonData="item.waterfallLayouts[index % item.waterfallLayouts.length]" :listData="obj" :dataBind="item.bindData"></myPage>
							<myPage v-if="item.type === 'mutiStyleList'" :childLevel="1" :pageConfig="pageConfig" :jsonData="item.mutiChildren[obj.styleLink]" :listData="obj" :dataBind="item.bindData"></myPage>
						</div>
						<div class="infoBox" :class="{waterfall:item.type === 'waterfall'}" :style="item.type === 'waterfall'?('top:'+item.maxH+'rpx;'):''">
							<u-loadmore :status="item.status" v-if="item.loadmoreShow" :margin-top="20" :margin-bottom="20"></u-loadmore>
							<u-empty text="暂无数据" mode="data" v-if="item.listArray.length === 0 && !item.loadmoreShow"></u-empty>
						</div>
					</template>
				</div>
			</block>

			<!-- 轮播图banner -->
			<block :key="item.cid" v-if="item.type === 'banner'">
				<div class="myBanner" v-if="!item.common.isHidden" :style="item.styleStr" @tap.stop>
					<swiper
						:indicator-dots="false"
						:autoplay="item.style.autoSliding"
						:interval="item.style.slidingInterval * 1000"
						:circular="item.listArray.length > 1 ? item.style.circular : false"
						:previous-margin="item.style.previousMargin + 'rpx'"
						:next-margin="item.style.nextMargin + 'rpx'"
						:vertical="item.style.direction==='ver'"
						@change="swiperChange($event, item)"
						ref="swiper"
					>
						<swiper-item v-for="(obj, index) in item.listArray" :key="index">
							<view @tap="handleTap(item, obj)" class="box" :style="'transform:scale(' + (item.current === index ? 1 : item.style.itemScale) + ');margin:0 ' + item.style.interitemSpacing / 2 + 'rpx;'">
								<myPage :childLevel="1" :pageConfig="pageConfig" :jsonData="item.children" :ref="'swiperPage-'+item.cid" :listData="obj" :dataBind="item.bindData"></myPage>
							</view>
						</swiper-item>
					</swiper>
					<mySwiperDot
						v-if="item.style.indicatorShow"
						:info="item.listArray"
						:current="item.current"
						:mode="item.style.indicatorStyle"
						:dotsStyles="item.dotsStyles"
						:vertical="item.style.direction==='ver'"
						:width="item.common.width"
						:height="item.common.height"
					></mySwiperDot>
				</div>
			</block>

			<!-- 标签页tabTitle -->
			<block :key="item.cid" v-if="item.type === 'tabTitle'">
				<div class="myTabTitle" v-if="!item.common.isHidden" :style="item.styleStr" @tap.stop>
					<m-tabs
						bgColor="transparent"
						name="text"
						:list="item.common.links"
						:current="item.activeIndex"
						@change="tabTitleChange($event,item)"
						:height="item.style.tabHeight"
						:font-size="item.style.textFont"
						:active-color="item.style.indicatorColor"
						:text-active-color="item.style.selectTextColor"
						:inactive-color="item.style.textColor"
						:item-width="item.style.tabItemWidth"
						:auto-width="item.style.autoWidth"
						:is-center="item.style.isCenter"
						:bold="item.style.bold"
						:active-font-size="item.style.selectTextFont"
						:bar-height="item.style.indicatorHeight"
						:bar-width="item.style.indicatorWidth"
						:indicator-img="item.style.indicatorImg"
						:indicator-x="item.style.indicatorMoveX"
						:indicator-y="item.style.indicatorMoveY"
					></m-tabs>
					<div class="tabs" v-for="(page, index) in item.common.links" :key="page.cid" v-show="item.activeIndex === index">
						<myPage v-if="item.pages[index]" :pageConfig="item.pages[index]" :jsonData="item.pages[index].page.content" parentCid="page" @pageGap="pageGapChange"></myPage>
					</div>
				</div>
			</block>
		</template>
	</div>
</template>
<script>
// vue组件
import myPage from './myPage.vue';
import mySwiperDot from './importedCom/my-swiper-dot/my-swiper-dot.vue';
import myNavBar from './importedCom/my-nav-bar/my-nav-bar.vue';
// 简单组件
import myImg from './myCom/myImg.vue';
import myButton from './myCom/myButton.vue';
import myWeather from './myCom/myWeather.vue';
import myLabel from './myCom/myLabel.vue';
import myScrollLabel from './myCom/myScrollLabel.vue';
import myCountDown from './myCom/myCountDown.vue';
import myLineProgress from './myCom/myLineProgress.vue';
import myInput from './myCom/myInput.vue';
import myRichText from './myCom/myRichText.vue';
import myVideo from './myCom/myVideo.vue';
import scanCode from './myCom/scanCode.vue';
import myTags from './myCom/myTags.vue';
import myMap from './myCom/myMap.vue';
import myPicPrev from './myCom/myPicPrev.vue';
// layout、list、banner、tabTitle等复杂组件的mixins
import layout from './mixins/layout.js';
import list from './mixins/list.js';
import banner from './mixins/banner.js';
import tabTitle from './mixins/tabTitle.js';
// 常用方法
import { handleDataBind, handleEvent, copy } from './libs/utils.js';
import ifTerminalTrue from './libs/ifTerminalTrue.js';
import calcBaseStyle from './libs/calcBaseStyle';
import listWidget from './libs/listWidget';
import seprateWidgets from './libs/seprateWidgets';
import windowHeight from './libs/windowHeight';
export default {
	name: 'myPage',
	mixins: [layout, list, banner, tabTitle],
	props: {
		listData: null,
		dataBind: null,
		level: null,
		parentCid: null,
		pageConfig: Object,
		jsonData: {
			type: Array,
			default(){
				return []
			}
		},
		childLevel: null,
		pcid: null
	},
	data() {
		return {
			liveJsonData: [],
			widgetList: [],
			loadedWidgets: [],
			oldScrollTop: 0,
			scrollTop: 0,
			listWidget: listWidget,
		};
	},
	inject: ['options'],
	components: { myPage, mySwiperDot, myNavBar, myImg, myButton, myWeather, myLabel, myScrollLabel, myCountDown, myLineProgress, myInput, myRichText, myVideo, scanCode, myTags, myMap, myPicPrev },
	created() {
		if(this.pcid){
			this.getParent().widgetList.some(widget=>{
				if(widget.cid === this.pcid){
					this.getContainerWidgetList(widget,this)
					this.afterCreated()
					return true
				}
			})
		}else{
			this.afterCreated()
		}
	},
	beforeDestroy() {
		this.removeOn()
		// #ifdef H5
		if(this.$editMode){
			this.widgetList.forEach(widget=>{
				if(widget.type === 'scrollView'){
					uni.$off('scrollView-'+widget.cid)
					uni.removeStorageSync('sv-'+widget.cid)
				}
			})
		}
		// #endif
	},
	methods: {
		getParent(oparent){
			var parent = oparent || this
			parent = parent.$parent
			if('widgetList' in parent){
				return parent
			}else{
				return this.getParent(parent)
			}
		},
		afterCreated(){
			this.scrollTop = 0;
			this.oldScrollTop = 0;
			this.widgetList = [];
			this.loadedWidgets = [];
			if(this.jsonData.length === 0 && this.liveJsonData.length === 0){
				return
			}
			this.initWidgets()
			this.removeOn()
			this.addOn()
		},
		addOn(){
			// 监听这一级的属性修改事件
			uni.$on('attr-'+this.pageConfig.cid+'-'+this.parentCid, this.onWidgetAttrChange)
			if(!this.$editMode){
				uni.$on('scrollToBot-'+this.pageConfig.cid,this.onPageScrollBot)
				if(this.parentCid === 'page'){
					uni.$on('h-gap-'+this.pageConfig.cid,this.onPageGapUpdate)
				}
			}
		},
		removeOn(){
			// 移除监听这一级的属性修改事件
			uni.$off('attr-'+this.pageConfig.cid+'-'+this.parentCid, this.onWidgetAttrChange)
			if(!this.$editMode){
				uni.$off('scrollToBot-'+this.pageConfig.cid,this.onPageScrollBot)
				if(this.parentCid === 'page'){
					uni.$off('h-gap-'+this.pageConfig.cid,this.onPageGapUpdate)
				}
			}
		},
		onWidgetAttrChange(payload){
			this.widgetList.some(item=>{
				if(item.cid === payload.targetCid){
					var attr = payload.attr
					if ((attr.type === 'clear' || attr.type === 'refresh') && !item.common.isHidden) {
						if(listWidget.indexOf(item.type)>-1){
							this.$set(item,'listArray',[])
							this.$set(item,'bindData',[])
							this.$set(item,'loadmoreShow',true)
							this.$set(item,'status','nomore')
						}else if(item.type === 'banner'){
							this.$set(item,'listArray',[])
							this.$set(item,'bindData',[])
						}
						if(attr.type === 'refresh'){
							uni.$emit('sendAjax-' + this.pageConfig.cid + '-' + payload.targetCid, {
								type: 'sendAjax',
							})
						}
					}else if(attr.type === 'show' || attr.type === 'hide' || attr.type === 'toggle'){
						var oldIshidden = item.common.isHidden
						if(attr.type === 'show' || attr.type === 'hide'){
							item.common.isHidden = attr.type === 'show' ? false : true
						}else{
							item.common.isHidden = !item.common.isHidden
						}
						if(oldIshidden && !item.common.isHidden){
							if(listWidget.indexOf(item.type) > -1 || item.type === 'banner' || item.type === 'tabTitle'){
								this.initOneWidget(item)
							}
						}
					}else if(attr.type === 'attr'){
						attr.attrList.forEach(nowAttr => {
							var nowTarget = item[nowAttr.attr.split('%krt_')[0]]
							var targetVal = nowAttr.target
							if(nowAttr.step){
								// 元素修改时递增或递减
								var lastVal = nowTarget[nowAttr.attr.split('%krt_')[1]]
								if(nowAttr.step === 'plus'){
									lastVal = lastVal + targetVal
								}else if(nowAttr.step === 'minus'){
									lastVal = lastVal - targetVal
								}
								targetVal = lastVal
							}else if((nowAttr.source === 'vari'||nowAttr.vari) && this.pageConfig.variable){
								// 元素属性修改时读取变量值
								this.pageConfig.variable.some(vari=>{
									if(vari.keyName===targetVal){
										targetVal = vari.val
										return true
									}
								})
							}else if(nowAttr.source === 'storage'){
								// #ifdef H5
								targetVal = localStorage.getItem(targetVal)
								// #endif
								// #ifdef MP
								targetVal = uni.getStorageSync(targetVal)
								// #endif
							}
							nowTarget[nowAttr.attr.split('%krt_')[1]] = targetVal
						})
						var ifReload = item.type === 'waterfall' && attr.attrList.some(nowAttr=>nowAttr.attr.indexOf('leftSpaceH') > -1)
						if(!ifReload){
							this.changeWidgetStyle(item)
							if(item.type === 'map' || item.type === 'weather'){
								this.initOneWidget(item)
							}
						}else{
							this.initOneWidget(item)
						}
					}
					return true
				}
			})
		},
		onPageScrollBot(){
			this.widgetList.forEach(item=>{
				if(listWidget.indexOf(item.type)>-1){
					this.listOnscrollBot(item)
				}
			})
		},
		scrollTopChange(){
			if(!this.$editMode && this.level === 1){
				// 页面滚动时,去加载可视区域内的组件
				if(this.scrollTop > this.oldScrollTop){
					this.oldScrollTop = this.scrollTop
					this.initWidgets();
				}
			}
		},
		onPageGapUpdate(gap){
			if(this.level === 1){
				uni.$emit('pageGap-' + this.pageConfig.cid, gap)
			}else{
				this.$emit('pageGap', gap)
			}
		},
		pageGapChange(gap){
			uni.$emit('pageGap-' + this.pageConfig.cid, gap)
		},
		// 初始化页面的方法，计算每个组件的样式，及其事件
		initWidgets(){
			// 第一步,获取组件列表,如果是第一级,则先筛选一下可视区域的组件来加载,并计算每个组件的样式及其事件
			var jsonData = this.getWidgets();
			// 第二部,处理数据及绑定数据
			jsonData.forEach((item,index) => {
				var newItem = item
				// 列表类型组件中的列表项数据需复制一份,仅需复制第一级元素
				if(this.listData && this.dataBind){
					if(this.childLevel === 1){
						newItem = copy(item)
					}
					newItem = handleDataBind(this.listData, this.dataBind, newItem);
					jsonData.splice(index,1,newItem)
				}
				this.initOneWidget(newItem)
			});
			
			// 第三步,将处理好的组件列表交给页面去渲染
			if(!this.$editMode && this.level === 1){
				this.widgetList = this.widgetList.concat(jsonData);
			}else{
				this.widgetList = jsonData
			}
		},
		setNestedWidgets(item){
			var nowWidget = null
			if(item.type === 'layout'){
				nowWidget = this.$refs['layoutPage-'+item.cid]
			}else if(item.type === 'scrollView'){
				nowWidget = this.$refs['scrollPage-'+item.cid]
			}else if(item.type === 'waterfall' && item.waterfallLt){
				nowWidget = this.$refs['listPageLt-'+item.cid]
			}
			nowWidget = nowWidget || []
			nowWidget.forEach(widget=>{
				this.getContainerWidgetList(item,widget)
				widget.afterCreated()
			})
		},
		getContainerWidgetList(item,widget){
			var children = item.children
			if(item.type === 'waterfall' && item.waterfallLt){
				children = item.waterfallLt
			}
			widget.liveJsonData = children
		},
		initOneWidget(item){
			// 计算组件的样式
			if(seprateWidgets.indexOf(item.type) > -1){
				var singleWidget = this.$refs[item.type+item.cid] || []
				singleWidget.forEach(widget=>{
					widget.item = item
					if(item.type === 'map' || item.type === 'weather'){
						widget.afterCreated()
					}
				})
			}else{
				if(item.type === 'layout' || item.type === 'scrollView' || (item.type === 'waterfall' && !item.common.isHidden && item.waterfallLt)){
					this.setNestedWidgets(item)
				}
				this.$set(item,'styleStr',calcBaseStyle(item,this.pageConfig.contentH) + this.calcInnerStyle(item))
			}

			// 如果是layout组件,则当它更新时,应该更新它内部的所有组件
			if(item.type === 'layout'){
				this.$set(item, 'shareInfo', this.shareInfo(item));	//设置layout的分享信息
				var layoutPage = this.$refs['layoutPage-'+item.cid] || []
				layoutPage.forEach(layout=>{
					layout.afterCreated()
				})
			}
			// 如果是scrollView组件,则当它更新时,应该更新它内部的所有组件
			if(item.type === 'scrollView'){
				var scrollPage = this.$refs['scrollPage-'+item.cid] || []
				scrollPage.forEach(scrollView=>{
					scrollView.afterCreated()
				})
			}
			// #ifdef H5
			if(this.$editMode && item.type === 'scrollView'){
				var scrollSv = uni.getStorageSync('sv-'+item.cid)
				if(scrollSv){
					var scInfo = scrollSv.split(',')
					item.common.scrollLeft = scInfo[0]
					item.common.scrollTop = scInfo[1]
				}
				uni.$on('scrollView-'+item.cid,payload=>{
					item.common.scrollLeft = payload.x
					item.common.scrollTop = payload.y
					uni.setStorageSync('sv-'+item.cid,payload.x+','+payload.y)
				})
			}
			// #endif
			// 如果是列表组件和瀑布流组件,则需计算子布局样式,并初始化
			if(listWidget.indexOf(item.type)>-1 && !item.common.isHidden){
				this.$set(item, 'listArray', []);	//设置列表数据的初始值
				this.$set(item, 'status', 'loading');	//设置列表的加载状态
				this.$set(item, 'loadmoreShow', true);	//设置列表的加载更多的文字是否出现
				if(item.type === 'waterfall'){
					this.$set(item, 'maxH', 0 + item.common.leftSpaceH);	//设置瀑布流的加载更多的文字出现的高度
				}
				this.$set(item,'itemStyle',this.listItemStyle(item))
				var listPageLt = this.$refs['listPageLt-'+item.cid] || []
				listPageLt.forEach(listPageLt=>{
					listPageLt.afterCreated()
				})
				this.initList(item,item.children);
			}
			// 如果是轮播图组件,则需初始化
			if (item.type === 'banner' && !item.common.isHidden) {
				this.$set(item, 'listArray', []);	//设置轮播图数据的初始值
				this.$set(item,'current',0);	//设置轮播初始高亮
				this.initBanner(item);
			}
			// 如果是标签页组件,则需初始化
			if(item.type === 'tabTitle' && !item.common.isHidden){
				this.$set(item, 'pages', []);	//设置标签页组件列表的初始值
				this.$set(item, 'activeIndex', 0);	//设置标签页默认高亮的下标
				this.initTabTitle(item);
			}
		},
		changeWidgetStyle(item){
			// 计算组件的样式
			if(seprateWidgets.indexOf(item.type) === -1){
				this.$set(item,'styleStr',calcBaseStyle(item,this.pageConfig.contentH) + this.calcInnerStyle(item))
			}
			
			// 如果是列表组件和瀑布流组件,则需计算子布局样式,并初始化
			if(listWidget.indexOf(item.type)>-1){
				this.$set(item,'itemStyle',this.listItemStyle(item))
			}
		},
		getWidgets(){
			var jsonData = [];
			var widgetData = [];
			if(this.jsonData.length > 0){
				widgetData = this.jsonData
			}else{
				widgetData = this.liveJsonData
			}
			widgetData.forEach(item=>{
				if(!ifTerminalTrue(item.common.terminal)){
					return
				}
				if(!this.$editMode && this.level === 1){
					// 先做筛选,筛选过的将跳过
					if(this.loadedWidgets.indexOf(item.cid) > -1){
						return
					}
					//可视区域内组件才渲染
					if(uni.upx2px(item.common.y) < windowHeight + this.oldScrollTop){
						this.loadedWidgets.push(item.cid);	//将已筛选的组件cid放入一个数组记录下来
						this.$set(item.common,'isHidden',item.common.isHidden ? true : false)
						jsonData.push(item);
					}
				}else{
					this.$set(item.common,'isHidden',item.common.isHidden ? true : false)
					jsonData.push(item);
				}
			});
			return jsonData
		},
		calcInnerStyle(item) {
			if (item.type === 'layout') {
				return this.layoutInnerStyle(item);
			}
			return '';
		},
		shareInfo(item){
			var shareInfo = {},hasShare = false;
			if (item.event) {
				hasShare = item.event.some(e => {
					if (e.type === 'sharePage') {
						shareInfo = e;
						// 如果此分享按钮上也绑定了发送链接的埋点,那么要把埋点配置也放到分享配置里去
						var buriedPointConfig = item.event.filter(e=>e.type === 'buriedPoint'&&e.itemCode === '001001')
						var tranConfig = buriedPointConfig.length > 0 ? buriedPointConfig[0] : undefined
						shareInfo.tranConfig = tranConfig
						return true;
					}
				});
			}
			return { hasShare, shareInfo };
		},
		handleTap(item, listItem) {
			handleEvent(item.event, listItem || {}, this.pageConfig, this.options);
		}
	}
};
</script>
<style lang="less" scoped>
@import './style/layout.less';
@import './style/list.less';
@import './style/banner.less';
@import './style/tabTitle.less';
@import './style/scrollView.less';
.myPage {
	position: relative;
}
</style>
